package org.firefligher.xscript;

import org.firefligher.xscript.exception.ParameterException;

public class Functions {
	public static int add(FunctionParameter[] parameters) {
		if(parameters.length == 2) {
			int i = Integer.parseInt(parameters[0].getContent());
			int j = Integer.parseInt(parameters[1].getContent());
			
			System.out.println(i + " + " + j + " = " + (i + j));
			
			return i + j;
		}
		
		throw new ParameterException("Not right number of paramters.");
	}

	public static int sub(FunctionParameter[] parameters) {
		if(parameters.length == 2) {
			int i = Integer.parseInt(parameters[0].getContent());
			int j = Integer.parseInt(parameters[1].getContent());
			
			System.out.println(i + " - " + j + " = " + (i - j));
			
			return i - j;
		}
		
		throw new ParameterException("Not right number of paramters.");
	}

	public static int mul(FunctionParameter[] parameters) {
		if(parameters.length == 2) {
			int i = Integer.parseInt(parameters[0].getContent());
			int j = Integer.parseInt(parameters[1].getContent());
			
			System.out.println(i + " * " + j + " = " + (i * j));
			
			return i * j;
		}
		
		throw new ParameterException("Not right number of paramters.");
	}

	public static int div(FunctionParameter[] parameters) {
		if(parameters.length == 2) {
			int i = Integer.parseInt(parameters[0].getContent());
			int j = Integer.parseInt(parameters[1].getContent());
			
			System.out.println(i + " / " + j + " = " + (i / j));
			
			return i / j;
		}
		
		throw new ParameterException("Not right number of paramters.");
	}
}
